<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:t="http://java.sun.com/jsf/composite/components/comps"
	xmlns:m="http://java.sun.com/jsf/composite/components/modalPesquisa"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
</h:head>
<h:body>
	<h:form id="frmPagina">

		<t:toolbar managedbean="#{perfilHome}" widgetVar="toolBar"></t:toolbar>

		<p:tabView>

			<p:tab title="Perfil" id="tabPerfil">
				<h:panelGrid columns="1">
					<h:outputLabel value="Nome" for="txtNome" />
					<p:inputText id="txtNome" value="#{perfilHome.entidade.nome}"
						disabled="#{!perfilHome.estadoCadastrando and !perfilHome.estadoEditando}"></p:inputText>

				</h:panelGrid>
			</p:tab>

			<p:tab title="Permissões" id="tabPermissao" rendered="#{perfilHome.estadoCadastrando or perfilHome.estadoEditando}">
				<p:tree value="#{perfilHome.root}" var="node"
					selection="#{perfilHome.nodeSelecionado}" selectionMode="single"
					nodeSelectListener="#{perfilHome.onNodeSelect}"
					update="frmLovPermissao" onselectComplete="lovPermissao.show()">
					<p:treeNode>
						<h:outputText value="#{node}" />
					</p:treeNode>
				</p:tree>
			</p:tab>

		</p:tabView>
	</h:form>


	<p:dialog id="dglPermissao" widgetVar="lovPermissao"
		header="Permissões">
		<h:form id="frmLovPermissao">
			<h:outputText value="Módulo #{perfilHome.moduloSelecionado.nome}" />
			<p:spacer height="20px"></p:spacer>
			<p:dataList value="#{perfilHome.permissoesModulo}" var="to">
				<p:column>
					<h:outputText value="#{to.permissao.funcionalidade.nome}" />
					<h:selectBooleanCheckbox value="#{to.ativo}" />
				</p:column>
			</p:dataList>
			
			<p:commandButton value="Aplicar" action="#{perfilHome.aplicarPermissoes}" oncomplete="lovPermissao.hide()"></p:commandButton>
		</h:form>
	</p:dialog>

	<p:dialog id="dglPesquisa" widgetVar="lovPesquisa"
		header="Pesquisar Perfil">
		<h:form id="frmLovPesquisa">
			<p:dataTable value="#{perfilHome.todos}"
				selection="#{perfilHome.entidade}" selectionMode="single"
				var="perfil" dblClickSelect="true"
				rowSelectListener="#{perfilHome.selecionar}"
				onRowSelectComplete="lovPesquisa.hide()" update="frmPagina">

				<p:column headerText="Código" filterBy="#{perfil.id}">
					<h:outputText value="#{perfil.id}" />
				</p:column>
				<p:column headerText="Nome" filterBy="#{perfil.nome}">
					<h:outputText value="#{perfil.nome}" />
				</p:column>
			</p:dataTable>
		</h:form>
	</p:dialog>

</h:body>
</html>